package com.lixin.config;

import com.lixin.interceptor.CorsInterceptor;
import com.lixin.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    @Autowired
    private CorsInterceptor corsInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(corsInterceptor);
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/admin/user/login");
        excludePath.add("/admin/user/register");
        excludePath.add("/admin/user/check_account");
        excludePath.add("/admin/user/test");
        registry.addInterceptor(loginInterceptor).excludePathPatterns(excludePath);
    }
}
